home *** CD-ROM | disk | FTP | other *** search
/ Cracking 2 / Cracking II..iso / Tools / ApiHooks 2.2 / examples / ASM / alternative / Alternative.txt < prev    next >
Encoding:
Text File  |  2000-04-04  |  1.9 KB  |  46 lines

  1.  This example demonstrates use of (Un)LoadModuleTime APIs and use of
  2. HOOKS_DYNAMIC with EXCLUDED module(s).
  3. 1) Alternative.dll is loaded into given process (here current process)
  4.    using LoadModuleTime.
  5. 2) Alternative calls EstablishApiHooks with HOOKS_DYNAMIC with one 
  6.    excluded module (Alternative.dll). API MessageBoxA is hooked.
  7. 3) Alternative.dll is unloaded using UnloadModuleTime.
  8.  
  9.  The same effect could be obtained if Alternative.dll would export
  10. hooks statically (and didn't ude dynamic hooks) and EstablishApiHooks
  11. would be called. The disadvantage of the 1st solution is that
  12. ApiHooks.dll must be present in given process.
  13.  (Even if EstablishApiHooks would be used with module with no hooks,
  14.  module is uploaded and dynamic hooks are applied, but hooks can't
  15.  be established and return value will be ErrorRemoteExec)
  16.  
  17.  If the dynamic hooks would be applied without excluded module
  18. (Alternative.dll) which hooks and imports given API (MessageBoxA)
  19. call to MessageBoxA would never end because MessageBoxA in the module
  20. which hooks it would point to a routine in this module:
  21.  NewMessageBoxA:
  22.   ...CALL [_imp__MessageBoxA]
  23.  but [_imp__MessageBoxA] == NewMessageBoxA
  24.  
  25.  
  26. How to exclude modules?
  27.  It is allowed in HOOKS_DYNAMIC only and applies to ALL_MODULES hooks.
  28. UnhookAddresses in the 1st API_HOOK structure (with HOOKS_DYNAMIC)
  29. must point to null terminated list of image bases.
  30.  
  31. In C syntax:
  32. API_HOOK ApiHookChain[x] = {
  33.  {HOOKS_DYNAMIC, NULL, 0,          NULL,   Excluded, NULL},
  34.  {ModExp,        Api,  Attributes, ModImp, UnhookApi, NewApi},
  35.  //...
  36.  {HOOKS_END}
  37. }
  38.  
  39. Excluded[N+1] = Base0, Base1, ... BaseN, NULL
  40.  
  41.  Then when ApiHooks should apply given hooks to ALL_MODULES it will
  42. compare actual module base with bases in exclude list. If it is found
  43. it'll not be hooked.
  44.  
  45.  Using HOOKS_DYNAMIC with excluded modules makes sense when .dll calls
  46. EstablishApiHooks* with hooks containing ALL_MODULES.